package com.cyw.note.controller;

import com.cyw.common.core.domain.R;
import com.cyw.note.entity.Note;
import com.cyw.note.service.NoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: Chenyw
 * @Date: 2022/08/22/16:34
 */

@Api("文章接口")
@RestController
@RequestMapping("/note")
public class NoteController {

    @Resource
    private NoteService noteService;

    @GetMapping("test")
    public R tt(){

        return R.ok();
    }

    @ApiOperation("分页查询文章")
    @GetMapping("findAllByPage")
    public R<Page<Note>> findAllByPage(int currentPage, int pageSize){
        return noteService.findAllByPage(currentPage,pageSize);
    }

    @ApiOperation("写/修改文章")
    @PostMapping("saveOrUpdateNote")
    public R<Note> saveOrUpdateNote(@RequestBody Note note){
        return noteService.saveOrUpdateNote(note);
    }

    @ApiOperation("删除文章")
    @DeleteMapping("{id}")
    public R removeNote(@PathVariable String id){
        return noteService.removeNote(id);
    }
}
